import time
import selenium
from selenium.webdriver import chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select


url = 'http://106.52.182.140/fanwe/index.php?ctl=user&act=login'
driver = selenium.webdriver.Chrome()
driver.get(url=url)
driver.maximize_window()    #浏览器窗口最大化
driver.implicitly_wait(10)  #设置隐式等待

#方维账号输入框中输入账号”
driver.find_element(By.XPATH,'//*[@id="page_login_form"]/div[1]/div[1]/input').send_keys("cxytest004")
#密码输入框中输入密码
driver.find_element(By.XPATH,"//*[@class='f-input ui-textbox' and @name='user_pwd']").send_keys("cxy123456")
#点击登录按钮登录
driver.find_element(By.ID,'user-login-submit').click()
xp = "/html/body/div[11]/table/tbody/tr/td[2]/div[3]/input[2]"
#点击取消，关闭弹窗
driver.find_element(By.XPATH,xp).click()
#点击个人资料，进入个人资料页面
time.sleep(3)
driver.find_element(By.XPATH,"//*[@class='user_info_d']/a[2]").click()
#点击编辑按钮，进入编辑个人资料页面
driver.find_element(By.ID,'edit-account').click()

#滚轮操作
driver.execute_script('window.scrollTo(0,400)')
time.sleep(3)
#修改省份select的属性将隐藏修改为可见
js = 'document.querySelectorAll("select")[1].style.display="block";'
driver.execute_script(js)
time.sleep(2)
#选择下拉框中的省份元素
xl_en = "/html/body/div[2]/div[3]/div[2]/form/table/tbody/tr[2]/td[2]/div[15]/div[8]/span/select[1]"
s_el = driver.find_element(By.XPATH,xl_en)
s = Select(s_el)
s.select_by_index(13)
time.sleep(2)

#修改城市select属性，将隐藏修改为可见
js_2 = 'document.querySelectorAll("select")[2].style.display="block";'
driver.execute_script(js_2)
time.sleep(2)
#通过select选择下拉框中的元素
el1 = "/html/body/div[2]/div[3]/div[2]/form/table/tbody/tr[2]/td[2]/div[15]/div[8]/span/select[2]"
s_el2 = driver.find_element(By.XPATH,el1)
s = Select(s_el2)
s.select_by_index(2)
time.sleep(2)

#点击保存
driver.find_element(By.ID,"settings-submit").click()